Skip to content

fix(windows): add Express path-rewriting middleware for Next.js static exports#2

Merged
itsbkm merged 1 commit into
FreeOpenSourcePOS:mainfrom
khaira777:pr2-express-fix
Jun 10, 2026
Merged

fix(windows): add Express path-rewriting middleware for Next.js static exports#2
itsbkm merged 1 commit into
FreeOpenSourcePOS:mainfrom
khaira777:pr2-express-fix

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

The Problem

There is a severe Next.js routing bug affecting local Windows development. On Windows, Next.js static exports (output: "export") use backslashes (\), which causes the build to generate nested directories (e.g., __next.A\B\__PAGE__.txt) instead of the expected flat files (e.g., __next.A.B.__PAGE__.txt).

When the client router requests the flat file with dots, Windows Express fails to find it. Instead of throwing a 404, the catch-all route silently serves index.html as a fallback. React attempts to parse this HTML as an RSC data payload and fails.

The Symptom: Because the payload fails to parse, React aborts the navigation. The app gets "stuck" on the current screen. Clicking sidebar links does nothing without a hard manual refresh, effectively breaking SPA navigation for local Windows developers.

(Note: This does not affect the official GitHub releases because CI/CD runs on Linux runners, which correctly generate the flat files).

The Solution

Added a lightweight Express middleware to both main/server.ts and main/kds-server.ts.

This middleware:

  1. Intercepts incoming requests containing __next..
  2. Rewrites the dotted segments into directory slashes.
  3. Checks fs.existsSync() to verify the nested Windows directory actually exists on disk.
  4. If it exists, it transparently rewrites req.url so express.static can serve the correct chunk.

Because of the fs.existsSync check, this middleware is a safe "no-op" on Linux/macOS machines and will not interfere with production CI/CD builds.

Testing

  • Windows (Local): Verified that navigating between pages (e.g., POS to Products) now successfully transitions the UI immediately instead of getting stuck on the same screen.
  • Builds: Ran npm run build and npm run build:frontend to confirm no compilation errors were introduced.

@itsbkm itsbkm merged commit f0ba38c into FreeOpenSourcePOS:main Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants